'''
=========================
!/usr/bin/env python
_*_ coding:utf-8 _*_

@Time : 2020/7/27 14:07
@Coder: xh
@IDE  : PyCharm
=========================
'''
import time
import re
from wxpy import *
from selenium import webdriver
from datetime import datetime
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get('https://kuaibao.qq.com/media/16466795?refer=spider')
time.sleep(3)
news_id = driver.find_element_by_xpath('/html/body/div/div/div[2]/div/div[3]/div[1]/li[1]').get_attribute('data-newsid')
news_url = f'https://kuaibao.qq.com/s/{news_id}?refer=spider'
driver.get(news_url)

news_list = []
title = '                    每日早报    '
news_list.append(title)
d = datetime.today()
today = str(d.year) + '年' + str(d.month) + '月' + str(d.day) + '日'
week_str ="星期一星期二星期三星期四星期五星期六星期日"
week_index = datetime.now().weekday()
weekday = today + '    ' + week_str[week_index*3:week_index*3+3]
news_list.append(weekday)
for i in range(3,15):
    try:
        news = driver.find_element_by_xpath(f'/html/body/div/div[2]/article/p[{i+1}]').text
        news.replace('、','.')
    except:
        pass
    news_list.append(news)
driver.get('http://mr.5156edu.com/')
remark = '\n' + '微语：' + driver.find_element_by_xpath('/html/body/table[3]/tbody/tr/td/table[1]/tbody/tr[3]/td').text
news_list.append(remark)
article = '\n'.join(news_list)
driver.close()
print(article)

bot = Bot()

my_friends = bot.friends().search(u'风吹沙')[0]
my_friends.send(article)